//
//  InviteContentView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/21.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "InviteContentView.h"
#import "InviteObj.h"
#import "BeeGroupListObj.h"
#import "UIImageView+WebCache.h"
#import "InviteCodeView.h"
#import "BeePhotoImageView.h"

@interface InviteContentView()
{
    BeeGroupListObj *beeObj;
    UIImageView *bgView;
    UIImageView *logoView;

    
    UILabel *beeName;
    UILabel *limitInfo;
    UILabel *beeTipsInfo;
    InviteCodeView *codeView;
    
    //底部
    BeePhotoImageView *photo;
    UILabel *nickName;
    UILabel *bottomInfo;
    UIImageView *qrCode;
    
    
}

@end

@implementation InviteContentView

-(instancetype)initWithFrame:(CGRect)frame obj:(BeeGroupListObj *)obj
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        beeObj = obj;
        
        [self buildView];
    }
    
    return self;
}

-(void)buildView
{
    bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    UIImage *img = [UIImage imageNamed:@"invite_bg"];
    img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(80, 10, 80, 10) resizingMode:UIImageResizingModeStretch];
    bgView.image = img;
    [self addSubview:bgView];
    
    logoView = [[UIImageView alloc] initWithFrame:CGRectMake(12.5, 12.5, self.width - 25, 140 * UISCALE)];
    //平铺
    [logoView setContentScaleFactor:[[UIScreen mainScreen] scale]];
    logoView.contentMode =  UIViewContentModeScaleAspectFill;
    logoView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    logoView.clipsToBounds  = YES;
    [logoView sd_setImageWithURL:[NSURL URLWithString:beeObj.logoUrl]];
    [self addSubview:logoView];
    
    UIImageView *blackV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, logoView.width, logoView.height)];
    blackV.backgroundColor = UIColorFromRGBA(0x000000, 0.5);
    [logoView addSubview:blackV];
    
    beeName = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(COLOR_WHITE).addFont([UIFont boldSystemFontOfSize:24.0f]);
        make.addText(beeObj.groupName);
        [make sizeToFit];
        make.center = logoView.center;
        [self addSubview:make];
    }];
    
    limitInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(UIColorFromRGB(0xF7B62D)).addFont([UIFont systemFontOfSize:16.0f]);
        make.addText(beeObj.inviteObj.rewardLimitTips);
        [make sizeToFit];
        make.top = logoView.bottom + 20;
        make.centerX = self.width/2;
        [self addSubview:make];
    }];
    
    beeTipsInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(UIColorFromRGB(0xF7B62D)).addFont([UIFont systemFontOfSize:25.0f]);
        make.addText(beeObj.inviteObj.rewardBeeTips);
        [make sizeToFit];
        make.top = limitInfo.bottom + 15;
        make.centerX = self.width/2;
        [self addSubview:make];
    }];
    
    codeView = [[InviteCodeView alloc] initWithFrame:CGRectMake(0, 0, 131*UISCALE, 70*UISCALE) Code:beeObj.inviteCode];
    codeView.centerX = self.width/2;
    codeView.bottom = self.height - 100*UISCALE;
    [self addSubview:codeView];
    
    
    photo = [[BeePhotoImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40) photoStyle:BeePhotoDefaultStyle];
    [photo setTitle:[UserInfoManager sharedManager].nickName];
    photo.left = 25;
    photo.bottom = self.height - 19;
    [self addSubview:photo];
    
    nickName = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(FBEE_COLOR_TEXT).addFont([UIFont systemFontOfSize:16.0f]);
        make.addText([UserInfoManager sharedManager].nickName);
        [make sizeToFit];
        make.top = photo.top;
        make.left = photo.right + 12;
        [self addSubview:make];
    }];
    
    bottomInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(FBEE_COLOR_INFO).addFont([UIFont systemFontOfSize:12.0f]);
        make.addText([NSString stringWithFormat:@"第%@位成员@%@",beeObj.joinSeq,beeObj.groupName]);
        [make sizeToFit];
        make.top = nickName.bottom + 5;
        make.left = photo.right + 12;
        [self addSubview:make];
    }];
    
    qrCode = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
    UIImage *qrImg = [UIImage encodeQRImageWithContent:beeObj.inviteObj.shareUrl size:CGSizeMake(120, 120)];
    qrCode.image = qrImg;
    qrCode.bottom = self.height - 8;
    qrCode.right = self.width - 10;
    [self addSubview:qrCode];
    
}

@end
